package com.se2.antiqueexhibition.Service.impl;

import com.se2.antiqueexhibition.Mapper.CommentMapper;
import com.se2.antiqueexhibition.Service.CommentService;
import com.se2.antiqueexhibition.pojo.Comment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    private CommentMapper commentMapper;

    @Override
    public boolean addComment(Comment comment) {
        // 新评论默认状态为待审核(0)
        comment.setStatus(0);
        return commentMapper.insert(comment) > 0;
    }

    @Override
    public Comment getCommentById(Integer id) {
        return commentMapper.selectById(id);
    }

    @Override
    public List<Comment> getCommentsByUserId(Integer userId) {
        return commentMapper.selectByUserId(userId);
    }

    @Override
    public List<Comment> getCommentsByTarget(String targetType, Integer targetId) {
        return commentMapper.selectByTarget(targetType, targetId);
    }

    @Override
    public List<Comment> getCommentsByStatus(Integer status) {
        return commentMapper.selectByStatus(status);
    }

    @Override
    public List<Comment> getAllComments() {
        return commentMapper.selectAll();
    }

    @Override
    public boolean updateComment(Comment comment) {
        return commentMapper.update(comment) > 0;
    }

    @Override
    public boolean approveComment(Integer id) {
        return commentMapper.updateStatus(id, 1) > 0;
    }

    @Override
    public boolean rejectComment(Integer id) {
        return commentMapper.updateStatus(id, 0) > 0;
    }

    @Override
    public boolean deleteComment(Integer id) {
        return commentMapper.deleteById(id) > 0;
    }

    @Override
    public boolean deleteCommentsByUserId(Integer userId) {
        return commentMapper.deleteByUserId(userId) > 0;
    }
}
